package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.ISendOrderForSuperView;
import com.cloudsigns.factorymanager2.engineering.model.ISendOrderForSuperModel;
import com.cloudsigns.factorymanager2.engineering.model.SendOrderForSuperModel;

/**
 * Created by tony on 2018/3/30.
 */

public class SendOrderForSuperPresenter {
    private ISendOrderForSuperView view;
    private ISendOrderForSuperModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public SendOrderForSuperPresenter(ISendOrderForSuperView view) {
        this.view = view;
        this.model = new SendOrderForSuperModel();
    }

    public void sendEngineeringOrder() {


        model.sendEngineeringOrder(view.getId(), view.getReceiveAccountId(), view.getEngineeringDeptOrderCategoryEnum(), new SendOrderForSuperModel.OnSendEngineeringOrderListener() {
            @Override
            public void successed() {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.diapatchSuccess();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.sendEngineeringOrderFailed(desc);
                        view.hideLoading();
                    }
                });
            }


        });
    }
}
